import requests
from dataclasses import dataclass, asdict

from framework.common_http import Request
from model.user import User, DefaultTestUser


class Login:
    def user_login(self, user: User or DefaultTestUser):
        # 用户登录接口
        # res = requests.post("https://litemall.hogwarts.ceshiren.com/wx/auth/login", json=asdict(user), verify=False)
        request = Request(
            method="POST",
            host="https://litemall.hogwarts.ceshiren.com",
            path="/wx/auth/login",
            type="json",
            json=asdict(user)
        )

        response = request.send()

        u_token = response.json().get("data").get("token")

        return u_token


if __name__ == '__main__':
    login = Login()
    login.user_login(DefaultTestUser())
